<?php
require_once './config.php';

$obj = array(
    'code' => 0,
    'msg' => '登录失败',
);

if (!isset($_REQUEST['username']) || !isset($_REQUEST['password'])) { // 判断参数是否传入
    $obj['msg'] = '缺少必要参数';
    die(json_encode($obj));
}

$username = $_REQUEST['username'];
$password = $_REQUEST['password'];

$sql = "SELECT * from denglu WHERE username = '$username'";

$result = mysqli_query($conn, $sql);

$data = mysqli_fetch_assoc($result);

if ($data) {
    if ($data['password'] === $password) {
        $obj['code'] = 1;
        $obj['msg'] = '登录成功';
    } else {
        $obj['msg'] = '用户名或者密码错误';
    }
} else {
    $obj['msg'] = '用户名或者密码错误';
}

echo json_encode($obj);
